package com.sina.weibo;

import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Bitmap.Config;
import android.graphics.Rect;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.ZoomControls;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import sudroid.android.CleanUtils;
import sudroid.android.DeviceUtil;
import sudroid.android.FileUtil;
import sudroid.android.graphics.BitmapUtils;

public class ImageViewer extends MobClientActivity
  implements View.OnClickListener
{
  private static final int DIALOG_ALERT_SAVE_BMP = 1000;
  private static final int DIALOG_PROGRESS_LOADING = 1001;
  protected static final int HIDE_ROTATE_BUTTONS = 3;
  protected static final int HIDE_ZOOM_CONTROLS = 2;
  static final String KEY_EXTRA_LOADMODE = "KEY_EXTRA_LOADMODE";
  static final String KEY_EXTRA_SIZE = "LOAD_MODE_SIZE";
  static final String KEY_EXTRA_URL = "KEY_EXTRA_URL";
  static final String LOAD_MODE_NET = "LOAD_MODE_NET";
  static final String LOAD_MODE_URI = "LOAD_MODE_URI";
  public static final int SIZE_TO_SCALE = 120;
  private File bmpFile;
  private Button btBack;
  private Button btSave;
  private Bitmap changedBmp;
  private String downloadSize;
  private Uri fileUri;
  Handler handler;
  private boolean isRotate;
  private ImageView ivDisplayImage;
  private AsyncTask<Void, Void, Uri> loadPicTask;
  private int maxWidth;
  private int minWidth;
  private View rotateBtns;
  private int rotateRate;
  private int scaledHeight;
  private int scaledWidth;
  private int srcHeight;
  private int srcWidth;
  private Bitmap srcbmp;
  private int titleHeight;
  private Uri uriHolder;
  private ZoomControls zcZooms;

  public ImageViewer()
  {
    ImageViewer.1 local1 = new ImageViewer.1(this);
    this.handler = local1;
    this.isRotate = 0;
    this.rotateRate = 0;
  }

  private void displayChangedBmp()
  {
    this.ivDisplayImage.setImageBitmap(null);
    this.changedBmp.recycle();
    if (this.rotateRate == 3)
    {
      Bitmap localBitmap1 = this.srcbmp;
      Bitmap.Config localConfig1 = Bitmap.Config.ARGB_4444;
      Bitmap localBitmap2 = BitmapUtils.createLeftRotatedBitmap(localBitmap1, localConfig1);
      this.changedBmp = localBitmap2;
    }
    while (true)
    {
      ImageView localImageView = this.ivDisplayImage;
      Bitmap localBitmap3 = this.changedBmp;
      perfectDisplay(localImageView, localBitmap3);
      return;
      if (this.rotateRate == 1)
      {
        Bitmap localBitmap4 = this.srcbmp;
        Bitmap.Config localConfig2 = Bitmap.Config.ARGB_4444;
        Bitmap localBitmap5 = BitmapUtils.createRightRotatedBitmap(localBitmap4, localConfig2);
        this.changedBmp = localBitmap5;
        continue;
      }
      if (this.rotateRate == 2)
      {
        Bitmap localBitmap6 = this.srcbmp;
        Bitmap.Config localConfig3 = Bitmap.Config.ARGB_4444;
        Bitmap localBitmap7 = BitmapUtils.create180RotatedBitmap(localBitmap6, localConfig3);
        this.changedBmp = localBitmap7;
        continue;
      }
      Bitmap localBitmap8 = this.srcbmp;
      Bitmap.Config localConfig4 = Bitmap.Config.ARGB_4444;
      Bitmap localBitmap9 = localBitmap8.copy(localConfig4, 1);
      this.changedBmp = localBitmap9;
    }
  }

  private void displayViews()
  {
    if (this.isRotate)
    {
      this.rotateBtns.setVisibility(0);
      this.handler.removeMessages(3);
      boolean bool1 = this.handler.sendEmptyMessageDelayed(3, 3000L);
    }
    while (true)
    {
      return;
      this.zcZooms.setVisibility(0);
      this.handler.removeMessages(2);
      boolean bool2 = this.handler.sendEmptyMessageDelayed(2, 3000L);
    }
  }

  private String getLargeImage(String paramString, boolean paramBoolean)
  {
    String str1 = getString(2131427630);
    if (!paramString.contains(str1))
      throw new RuntimeException("Pls make sure url contains \"wap\" chars.");
    try
    {
      String str2 = String.valueOf(getCacheDir().getAbsolutePath());
      String str3 = str2 + "/large_imgs";
      if (!FileUtil.doesExisted(str3))
        boolean bool = new File(str3).mkdirs();
      String str4 = this.downloadSize;
      String str5 = paramString.replace(str1, str4);
      String str6 = RPCHelper.getInstance(getApplication()).getPicture(str5, str3, paramBoolean);
      str7 = str6;
      return str7;
    }
    catch (RPCHelper.HttpException localHttpException)
    {
      while (true)
        String str7 = null;
    }
  }

  private void hideViews()
  {
    if (this.isRotate)
      boolean bool1 = this.handler.sendEmptyMessageDelayed(3, 4000L);
    while (true)
    {
      return;
      boolean bool2 = this.handler.sendEmptyMessageDelayed(2, 4000L);
    }
  }

  private void initBmpDisplaying(ImageView paramImageView)
  {
    Rect localRect = new Rect();
    DeviceUtil.getScreenRect(this, localRect);
    double d1 = localRect.width();
    Bitmap.Config localConfig1 = Bitmap.Config.ARGB_4444;
    int i = this.srcWidth;
    int j = this.srcHeight;
    int k = BitmapUtils.getMaxBound(6291456L, localConfig1, i, j).width();
    this.maxWidth = k;
    double d2 = this.maxWidth;
    double d3 = d1 * 1.5D;
    if (d2 > d3)
    {
      double d4 = d1 * 1.5D;
      int n = (int)d4;
      this.maxWidth = n;
      StringBuilder localStringBuilder = new StringBuilder("最大宽度为:");
      int i1 = this.maxWidth;
      Utils.logd(i1);
      int i2 = this.srcWidth;
      if (d1 <= i2)
        break label301;
      int m = this.srcWidth;
      label149: this.minWidth = m;
      this.scaledWidth = 0;
      this.scaledHeight = 0;
      if (this.srcWidth <= d1)
        break label307;
      this.scaledWidth = d1;
      int i3 = this.scaledWidth;
      int i4 = this.srcHeight;
      int i5 = i3 * i4;
      int i6 = this.srcWidth;
      int i7 = i5 / i6;
      this.scaledHeight = i7;
      this.ivDisplayImage.setImageBitmap(null);
      CleanUtils.recycleBitmap(this.changedBmp);
      Bitmap localBitmap1 = this.srcbmp;
      int i8 = this.scaledWidth;
      int i9 = this.scaledHeight;
      Bitmap.Config localConfig2 = Bitmap.Config.ARGB_4444;
      Bitmap localBitmap2 = BitmapUtils.createScaledBitmap(localBitmap1, i8, i9, localConfig2);
      this.changedBmp = localBitmap2;
      Bitmap localBitmap3 = this.changedBmp;
      perfectDisplay(paramImageView, localBitmap3);
    }
    while (true)
    {
      makesureZoomControls();
      return;
      double d5 = this.maxWidth;
      break;
      label301: d5 = d1;
      break label149;
      label307: int i10 = this.srcWidth;
      this.scaledWidth = i10;
      int i11 = this.srcHeight;
      this.scaledHeight = i11;
      this.ivDisplayImage.setImageBitmap(null);
      CleanUtils.recycleBitmap(this.changedBmp);
      Bitmap localBitmap4 = this.srcbmp;
      Bitmap.Config localConfig3 = Bitmap.Config.ARGB_4444;
      Bitmap localBitmap5 = localBitmap4.copy(localConfig3, 1);
      this.changedBmp = localBitmap5;
      Bitmap localBitmap6 = this.changedBmp;
      perfectDisplay(paramImageView, localBitmap6);
    }
  }

  private void initLayoutAndData()
  {
    Intent localIntent = getIntent();
    String str1 = localIntent.getStringExtra("KEY_EXTRA_LOADMODE");
    if (TextUtils.isEmpty(str1))
    {
      Utils.loge("pass over a wrong param.");
      finish();
    }
    while (true)
    {
      return;
      if (str1.equals("LOAD_MODE_NET"))
      {
        String str2 = localIntent.getStringExtra("LOAD_MODE_SIZE");
        this.downloadSize = str2;
        String str3 = localIntent.getStringExtra("KEY_EXTRA_URL");
        ImageViewer.3 local3 = new ImageViewer.3(this, str3);
        Void[] arrayOfVoid = new Void[0];
        AsyncTask localAsyncTask = local3.execute(arrayOfVoid);
        this.loadPicTask = localAsyncTask;
        continue;
      }
      if (!str1.equals("LOAD_MODE_URI"))
        continue;
      Uri localUri = localIntent.getData();
      prepareImage(localUri);
      this.zcZooms.setVisibility(8);
      this.rotateBtns.setVisibility(0);
      this.isRotate = 1;
    }
  }

  private boolean makesureSizeNotTooLarge(Rect paramRect)
  {
    int i = paramRect.width();
    int j = paramRect.height();
    if (i * j * 2 > 5242880);
    for (int k = 0; ; k = 1)
      return k;
  }

  private void makesureZoomControls()
  {
    int i = this.scaledWidth;
    int j = this.minWidth;
    if (i <= j)
    {
      this.zcZooms.setIsZoomOutEnabled(0);
      int k = this.scaledWidth;
      int m = this.maxWidth;
      if (k < m)
        break label63;
      this.zcZooms.setIsZoomInEnabled(0);
    }
    while (true)
    {
      return;
      this.zcZooms.setIsZoomOutEnabled(1);
      break;
      label63: this.zcZooms.setIsZoomInEnabled(1);
    }
  }

  private void perfectDisplay(ImageView paramImageView, Bitmap paramBitmap)
  {
    Rect localRect = new Rect();
    DeviceUtil.getScreenRect(this, localRect);
    int i = localRect.width();
    int j = localRect.height();
    int k = paramBitmap.getWidth();
    int m = paramBitmap.getHeight();
    int n = 0;
    int i1 = 0;
    if (k < i)
      n = (i - k) / 2;
    int i2 = this.titleHeight;
    int i3 = j - i2;
    if (m < i3)
    {
      int i4 = this.titleHeight;
      i1 = (j - i4 - m) / 2;
    }
    paramImageView.setPadding(n, i1, 0, 0);
    paramImageView.setImageBitmap(paramBitmap);
  }

  private void prepareImage(Uri paramUri)
  {
    Rect localRect;
    int i;
    int j;
    if ((paramUri != null) && (paramUri.getScheme().equals("file")))
    {
      this.uriHolder = paramUri;
      if (!FileUtil.doesExisted(this.bmpFile))
      {
        String str = paramUri.getPath();
        File localFile1 = new File(str);
        this.bmpFile = localFile1;
      }
      localRect = new Rect();
      i = 0;
      j = 0;
      if (j >= 1024)
      {
        label74: Utils.logd("放缩系数:" + i);
        Bitmap localBitmap = BitmapUtils.createZoomOutBitmap(this.bmpFile, i);
        this.srcbmp = localBitmap;
        if (this.srcbmp != null)
          break label175;
        finish();
      }
    }
    while (true)
    {
      return;
      File localFile2 = this.bmpFile;
      double d = j;
      i = (int)Math.pow(2.0D, d);
      boolean bool = BitmapUtils.getZoomOutBitmapBound(localFile2, i, localRect);
      if (makesureSizeNotTooLarge(localRect))
        break label74;
      j += 1;
      break;
      label175: int k = this.srcbmp.getWidth();
      this.srcWidth = k;
      int m = this.srcbmp.getHeight();
      this.srcHeight = m;
      ImageView localImageView = this.ivDisplayImage;
      initBmpDisplaying(localImageView);
      continue;
      finish();
    }
  }

  private void saveBmp()
  {
    if (FileUtil.hasSDCardMounted())
    {
      String str1 = String.valueOf(FileUtil.printSDCardRoot());
      StringBuilder localStringBuilder = new StringBuilder(str1).append("/sina/weibo/").append("img-");
      long l = System.currentTimeMillis();
      String str2 = l + ".jpg";
      Object[] arrayOfObject = new Object[1];
      arrayOfObject[0] = str2;
      String str3 = getString(2131427345, arrayOfObject);
      Toast localToast1 = Toast.makeText(this, str3, 0);
      Toast localToast2 = Toast.makeText(this, 2131427346, 0);
      new ImageViewer.4(this, str2, localToast1, localToast2).start();
    }
    while (true)
    {
      return;
      Toast.makeText(this, 2131427598, 0).show();
    }
  }

  private void saveChangedBmpFile()
  {
    if ((FileUtil.doesExisted(this.bmpFile)) && (isFinishing()) && (this.isRotate) && (this.changedBmp != null) && (this.rotateRate != 0));
    try
    {
      FileUtil.createNewFile(this.bmpFile);
      File localFile = this.bmpFile;
      FileOutputStream localFileOutputStream = new FileOutputStream(localFile);
      BufferedOutputStream localBufferedOutputStream = new BufferedOutputStream(localFileOutputStream);
      Bitmap localBitmap = this.changedBmp;
      Bitmap.CompressFormat localCompressFormat = Bitmap.CompressFormat.JPEG;
      boolean bool = localBitmap.compress(localCompressFormat, 100, localBufferedOutputStream);
      localBufferedOutputStream.close();
      label95: return;
    }
    catch (IOException localIOException)
    {
      break label95;
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      break label95;
    }
  }

  private void turnLeft()
  {
    int i = this.rotateRate - 1;
    this.rotateRate = i;
    int j = this.rotateRate % 4;
    this.rotateRate = j;
    if (j >= 0);
    for (int k = this.rotateRate; ; k = this.rotateRate + 4)
    {
      this.rotateRate = k;
      displayChangedBmp();
      return;
    }
  }

  private void turnRight()
  {
    int i = this.rotateRate + 1;
    this.rotateRate = i;
    int j = this.rotateRate % 4;
    this.rotateRate = j;
    if (j >= 0);
    for (int k = this.rotateRate; ; k = this.rotateRate + 4)
    {
      this.rotateRate = k;
      displayChangedBmp();
      return;
    }
  }

  public void onClick(View paramView)
  {
    switch (paramView.getId())
    {
    case 2131624011:
    case 2131624013:
    case 2131624014:
    case 2131624015:
    case 2131624016:
    default:
    case 2131624010:
    case 2131624012:
    case 2131624017:
    case 2131624018:
    }
    while (true)
    {
      return;
      finish();
      continue;
      saveBmp();
      continue;
      turnLeft();
      displayViews();
      continue;
      turnRight();
      displayViews();
    }
  }

  public void onConfigurationChanged(Configuration paramConfiguration)
  {
    super.onConfigurationChanged(paramConfiguration);
    if (this.fileUri != null)
    {
      Uri localUri = this.fileUri;
      prepareImage(localUri);
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903055);
    ImageView localImageView1 = (ImageView)findViewById(2131624014);
    this.ivDisplayImage = localImageView1;
    ImageView localImageView2 = this.ivDisplayImage;
    ImageViewer.2 local2 = new ImageViewer.2(this);
    localImageView2.setOnTouchListener(local2);
    int i = getResources().getDimensionPixelSize(2131296268);
    this.titleHeight = i;
    Button localButton1 = (Button)findViewById(2131624010);
    this.btBack = localButton1;
    this.btBack.setTextColor(-1);
    this.btBack.setOnClickListener(this);
    Button localButton2 = (Button)findViewById(2131624012);
    this.btSave = localButton2;
    this.btSave.setTextColor(-1);
    this.btSave.setOnClickListener(this);
    this.btSave.setClickable(0);
    ZoomControls localZoomControls1 = (ZoomControls)findViewById(2131624015);
    this.zcZooms = localZoomControls1;
    ZoomControls localZoomControls2 = this.zcZooms;
    ZoomInClickListener localZoomInClickListener = new ZoomInClickListener(null);
    localZoomControls2.setOnZoomInClickListener(localZoomInClickListener);
    ZoomControls localZoomControls3 = this.zcZooms;
    ZoomOutClickListener localZoomOutClickListener = new ZoomOutClickListener(null);
    localZoomControls3.setOnZoomOutClickListener(localZoomOutClickListener);
    View localView = findViewById(2131624016);
    this.rotateBtns = localView;
    findViewById(2131624017).setOnClickListener(this);
    findViewById(2131624018).setOnClickListener(this);
    initLayoutAndData();
    hideViews();
  }

  protected Dialog onCreateDialog(int paramInt)
  {
    Object localObject = null;
    switch (paramInt)
    {
    default:
    case 1000:
    case 1001:
    }
    while (true)
    {
      return localObject;
      View localView = getLayoutInflater().inflate(2130903091, null);
      EditText localEditText = (EditText)localView.findViewById(2131624163);
      AlertDialog.Builder localBuilder = new AlertDialog.Builder(this).setTitle(2131427626).setView(localView).setPositiveButton(2131427436, null);
      ImageViewer.5 local5 = new ImageViewer.5(this, localEditText);
      localObject = localBuilder.setPositiveButton(2131427441, local5).create();
      continue;
      localObject = new ProgressDialog(this);
      ProgressDialog localProgressDialog = (ProgressDialog)localObject;
      String str = getString(2131427422);
      localProgressDialog.setMessage(str);
    }
  }

  protected void onDestroy()
  {
    CleanUtils.recycleBitmap(this.changedBmp);
    CleanUtils.recycleBitmap(this.srcbmp);
    boolean bool = CleanUtils.cancelTask(this.loadPicTask);
    super.onDestroy();
  }

  protected void onPause()
  {
    super.onPause();
    saveChangedBmpFile();
  }

  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    displayViews();
    return super.onTouchEvent(paramMotionEvent);
  }

  class ZoomInClickListener
    implements View.OnClickListener
  {
    private ZoomInClickListener()
    {
    }

    public void onClick(View paramView)
    {
      int i = ImageViewer.this.scaledWidth;
      int j = ImageViewer.this.maxWidth;
      if (i < j)
      {
        ImageViewer localImageViewer1 = ImageViewer.this;
        int k = localImageViewer1.scaledWidth + 120;
        localImageViewer1.scaledWidth = k;
        ImageViewer localImageViewer2 = ImageViewer.this;
        int m = ImageViewer.this.scaledWidth;
        int n = ImageViewer.this.srcHeight;
        int i1 = m * n;
        int i2 = ImageViewer.this.srcWidth;
        int i3 = i1 / i2;
        localImageViewer2.scaledHeight = i3;
        ImageViewer.this.ivDisplayImage.setImageBitmap(null);
        CleanUtils.recycleBitmap(ImageViewer.this.changedBmp);
        ImageViewer localImageViewer3 = ImageViewer.this;
        Bitmap localBitmap1 = ImageViewer.this.srcbmp;
        int i4 = ImageViewer.this.scaledWidth;
        int i5 = ImageViewer.this.scaledHeight;
        Bitmap.Config localConfig = Bitmap.Config.ARGB_4444;
        Bitmap localBitmap2 = BitmapUtils.createScaledBitmap(localBitmap1, i4, i5, localConfig);
        localImageViewer3.changedBmp = localBitmap2;
        ImageViewer localImageViewer4 = ImageViewer.this;
        ImageView localImageView = ImageViewer.this.ivDisplayImage;
        Bitmap localBitmap3 = ImageViewer.this.changedBmp;
        localImageViewer4.perfectDisplay(localImageView, localBitmap3);
        ImageViewer.this.makesureZoomControls();
      }
    }
  }

  class ZoomOutClickListener
    implements View.OnClickListener
  {
    private ZoomOutClickListener()
    {
    }

    public void onClick(View paramView)
    {
      int i = ImageViewer.this.scaledWidth;
      int j = ImageViewer.this.minWidth;
      if (i > j)
      {
        ImageViewer localImageViewer1 = ImageViewer.this;
        int k = localImageViewer1.scaledWidth - 120;
        localImageViewer1.scaledWidth = k;
        ImageViewer localImageViewer2 = ImageViewer.this;
        int m = ImageViewer.this.scaledWidth;
        int n = ImageViewer.this.srcHeight;
        int i1 = m * n;
        int i2 = ImageViewer.this.srcWidth;
        int i3 = i1 / i2;
        localImageViewer2.scaledHeight = i3;
        ImageViewer.this.ivDisplayImage.setImageBitmap(null);
        CleanUtils.recycleBitmap(ImageViewer.this.changedBmp);
        ImageViewer localImageViewer3 = ImageViewer.this;
        Bitmap localBitmap1 = ImageViewer.this.srcbmp;
        int i4 = ImageViewer.this.scaledWidth;
        int i5 = ImageViewer.this.scaledHeight;
        Bitmap.Config localConfig = Bitmap.Config.ARGB_4444;
        Bitmap localBitmap2 = BitmapUtils.createScaledBitmap(localBitmap1, i4, i5, localConfig);
        localImageViewer3.changedBmp = localBitmap2;
        ImageViewer localImageViewer4 = ImageViewer.this;
        ImageView localImageView = ImageViewer.this.ivDisplayImage;
        Bitmap localBitmap3 = ImageViewer.this.changedBmp;
        localImageViewer4.perfectDisplay(localImageView, localBitmap3);
        ImageViewer.this.makesureZoomControls();
      }
    }
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     com.sina.weibo.ImageViewer
 * JD-Core Version:    0.6.0
 */